package com.huawei.appmarket.service.appdetail.view.card;

import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.a;
import androidx.recyclerview.widget.RecyclerView.s;
import com.huawei.appgallery.horizontalcard.api.view.BounceHorizontalRecyclerView;
import com.huawei.appgallery.jsonkit.api.JsonBean;
import com.huawei.appmarket.service.appdetail.bean.detail.DetailScreenBean;
import com.huawei.appmarket.service.appdetail.bean.detail.DetailScreenBean.DetailVideoInfo;
import com.huawei.appmarket.service.appdetail.view.GalleryActivityProtocol;
import com.huawei.appmarket.service.appdetail.view.GalleryActivityProtocol.Request;
import com.huawei.appmarket.support.video.VideoPlayer;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant.KeyAndValue;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import o.chc;
import o.cjk;
import o.cjm;
import o.cjo;
import o.cwv;
import o.dgh;
import o.doo;
import o.ContentManager;
import o.dra;
import o.drl;
import o.epv;
import o.CollectCheck;
import o.eqw;
import o.eqx;
import o.ActivityUtil;
import o.MinimumFactory;
import o.evn;
import o.evr;
import o.evt;
import o.ewm.h;
import o.ewm.j;
import o.ewm.n;

@SuppressLint({"InflateParams"})
public class DetailScreenCard extends drl {
    private BounceHorizontalRecyclerView ʻ;
    private b ʻॱ;
    private boolean ʼ;
    private int ʽ;
    private int ˊॱ;
    private Map<Integer, DetailVideoInfo> ˋॱ;
    private int ˏॱ;
    private boolean ͺ;
    private HashMap<ImageView, Integer> ॱˊ;
    private int ॱˋ;
    private List<DetailVideoInfo> ॱˎ;
    private DetailScreenBean ॱॱ;
    private ArrayList<String> ॱᐝ;
    private int ᐝॱ;

    class b extends BroadcastReceiver {
        private final Handler ˊ;
        final /* synthetic */ DetailScreenCard ˏ;
        private final Runnable ॱ;

        private b(DetailScreenCard detailScreenCard) {
            this.ˏ = detailScreenCard;
            this.ˊ = new Handler();
            this.ॱ = new Runnable(this) {
                final /* synthetic */ b ˎ;

                {
                    this.ˎ = r1;
                }

                public void run() {
                    evn ˎ = evr.ˊ().ˎ();
                    if (ˎ != null) {
                        ˎ.ʼ();
                    }
                }
            };
        }

        public void onReceive(Context context, Intent intent) {
            int ˊ = doo.ˊ(((ConnectivityManager) ContentManager.getInstant().getContext().getSystemService("connectivity")).getActiveNetworkInfo());
            if (ˊ != this.ˏ.ᐝॱ) {
                this.ˏ.ᐝॱ = ˊ;
                if (doo.ˊ(context)) {
                    this.ˊ.removeCallbacks(this.ॱ);
                    evn ˎ = evr.ˊ().ˎ();
                    if (ˎ != null) {
                        ˎ.ʼ();
                        return;
                    }
                    return;
                }
                this.ˊ.postDelayed(this.ॱ, 2000);
            }
        }
    }

    static class d extends s {
        private VideoPlayer ॱˋ;
        private View ᐝॱ;

        private d(View view) {
            super(view);
            this.ॱˋ = (VideoPlayer) view.findViewById(j.ᶥ);
            this.ᐝॱ = view.findViewById(j.ㆍ);
        }
    }

    class e extends a<s> implements OnClickListener {
        final /* synthetic */ DetailScreenCard ˊ;

        public e(DetailScreenCard detailScreenCard) {
            this.ˊ = detailScreenCard;
        }

        public s ˎ(ViewGroup viewGroup, int i) {
            return new d(LayoutInflater.from(this.ˊ.ˊ.getContext()).inflate(h.ॱͺ, null));
        }

        public void ॱ(s sVar, int i) {
            if (sVar instanceof d) {
                String ˏ;
                int intValue;
                DetailVideoInfo detailVideoInfo = (DetailVideoInfo) this.ˊ.ॱˎ.get(i);
                d dVar = (d) sVar;
                if (this.ˊ.ͺ) {
                    ˏ = detailVideoInfo.ˏ();
                } else {
                    ˏ = null;
                }
                dVar.ॱˋ.setVideoTag(detailVideoInfo.ˊ());
                dVar.ॱˋ.setVideoBaseInfo(new o.evp.b().ˎ(detailVideoInfo.ᐝ()).ˊ(detailVideoInfo.ʽ()).ˋ(ˏ).ॱ(detailVideoInfo.ʼ()).ʼ(detailVideoInfo.ˋॱ()).ᐝ(detailVideoInfo.ͺ()).ʻ(evt.ˏ(detailVideoInfo.sp_)).ॱ());
                if (this.ˊ.ˋॱ == null) {
                    intValue = Integer.valueOf(i).intValue();
                } else {
                    intValue = Integer.valueOf(i).intValue() - this.ˊ.ˋॱ.size();
                }
                this.ˊ.ॱˊ.put(dVar.ॱˋ.ॱॱ(), Integer.valueOf(intValue));
                if (MinimumFactory.getBoolValue(ContentManager.getInstant().getContext())) {
                    this.ˊ.ˏ(dVar.ᐝॱ, i, ˏ());
                } else {
                    this.ˊ.ˎ(dVar.ᐝॱ, i, ˏ());
                }
                dVar.ॱˋ.ॱॱ().setOnClickListener(this);
                if (this.ˊ.ˋॱ == null || i >= this.ˊ.ˋॱ.size()) {
                    eqw.ˋ(dVar.ॱˋ.ॱॱ(), detailVideoInfo.ʽ(), this.ˊ.ʼ, "app_default_icon");
                } else {
                    eqx.ˏ(dVar.ॱˋ.ॱॱ(), detailVideoInfo.ʽ(), "app_default_icon");
                }
            }
        }

        public int ˏ() {
            return this.ˊ.ॱˎ == null ? 0 : this.ˊ.ॱˎ.size();
        }

        public long ˏ(int i) {
            return (long) i;
        }

        public void onClick(View view) {
            if (view != null && (view instanceof ImageView) && this.ˊ.ͺ) {
                Context context = view.getContext();
                int intValue = ((Integer) this.ˊ.ॱˊ.get(view)).intValue();
                cjo galleryActivityProtocol = new GalleryActivityProtocol();
                Request request = new Request();
                request.ˊ(this.ˊ.ʼ);
                request.ˎ(intValue);
                request.ˋ(this.ˊ.ॱᐝ);
                galleryActivityProtocol.ˎ(request);
                cjk.ˎ().ˋ(context, new cjm("gallery.activity", galleryActivityProtocol));
                dgh.onEvent(new o.dge.d(context, n.ˎˏ).ˏ(KeyAndValue.NUMBER_01).ˋ());
            }
        }
    }

    public DetailScreenCard() {
        this.ʽ = ContentManager.getInstant().getContext().getResources().getDimensionPixelSize(o.ewm.d.ˏॱ);
        this.ॱॱ = null;
        this.ʼ = false;
        this.ˋॱ = null;
        this.ॱˊ = new HashMap();
        this.ͺ = true;
        this.ॱᐝ = new ArrayList();
        this.ॱ = 301;
    }

    public View ˊ(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        this.ˊ = layoutInflater.inflate(h.ॱʽ, null);
        this.ʻ = (BounceHorizontalRecyclerView) this.ˊ.findViewById(j.ˏ);
        return this.ˊ;
    }

    public static int ᐝ() {
        return chc.ˊˋ();
    }

    public boolean ˊ(List<JsonBean> list) {
        if (list == null || list.size() <= 0 || this.ʻ == null) {
            return false;
        }
        this.ॱॱ = (DetailScreenBean) list.get(0);
        if (!ʽ()) {
            return false;
        }
        this.ॱᐝ = this.ॱॱ.ˊ();
        this.ʼ = ˎ(this.ॱॱ.ʽ());
        if (this.ʼ) {
            this.ˊॱ = epv.ˎ(ContentManager.getInstant().getContext(), ᐝ(), this.ʽ);
            this.ˏॱ = (int) (((float) this.ˊॱ) * epv.ʼ());
        } else {
            this.ˊॱ = Math.round(ContentManager.getInstant().getContext().getResources().getDimension(o.ewm.d.ʼˋ));
            this.ˏॱ = Math.round(ContentManager.getInstant().getContext().getResources().getDimension(o.ewm.d.ʻᐝ));
        }
        if (!CollectCheck.isEmpty(this.ॱॱ.ᶥ())) {
            this.ˋॱ = new LinkedHashMap();
            for (DetailVideoInfo detailVideoInfo : this.ॱॱ.ᶥ()) {
                this.ˋॱ.put(Integer.valueOf(detailVideoInfo.ॱ()), detailVideoInfo);
            }
            this.ᐝॱ = doo.ˊ(((ConnectivityManager) ContentManager.getInstant().getContext().getSystemService("connectivity")).getActiveNetworkInfo());
            if (this.ʻॱ == null) {
                this.ʻॱ = new b();
                ActivityUtil.registerReceiver(ContentManager.getInstant().getContext(), new IntentFilter("android.net.conn.CONNECTIVITY_CHANGE"), this.ʻॱ);
            }
        }
        if (this.ॱˎ == null) {
            this.ॱˎ = new ArrayList();
        } else {
            this.ॱˎ.clear();
        }
        ʻ();
        cwv.ॱ().ˎ((String) this.ॱᐝ.get(0));
        cwv.ॱ().ˎ(this.ʼ);
        return true;
    }

    private boolean ʽ() {
        if (this.ॱॱ == null || this.ॱॱ.ˊ() == null || this.ॱॱ.ˊ().size() <= 0 || this.ॱॱ.ॱ() == null || this.ॱॱ.ॱ().size() <= 0) {
            return false;
        }
        return true;
    }

    private boolean ˎ(String str) {
        return DetailScreenBean.IMG_TAG_HORIZENTAL.equals(str);
    }

    private void ʻ() {
        boolean z;
        boolean z2;
        if (this.ˋॱ == null) {
            z = false;
        } else {
            z = this.ˋॱ.size();
        }
        for (z2 = false; z2 < z; z2++) {
            DetailVideoInfo detailVideoInfo = (DetailVideoInfo) this.ˋॱ.get(Integer.valueOf(z2));
            if (detailVideoInfo != null) {
                detailVideoInfo.ˏ(detailVideoInfo.ˋ());
                this.ॱˎ.add(detailVideoInfo);
            }
        }
        z = this.ॱॱ.ॱ() == null ? false : this.ॱॱ.ॱ().size();
        for (z2 = false; z2 < z; z2++) {
            String str = (String) this.ॱॱ.ॱ().get(z2);
            if (!(TextUtils.isEmpty(str) || ˏ(str))) {
                DetailVideoInfo detailVideoInfo2 = new DetailVideoInfo();
                detailVideoInfo2.ˏ(str);
                this.ॱˎ.add(detailVideoInfo2);
            }
        }
        a eVar = new e(this);
        eVar.ˋ(true);
        RecyclerView.j linearLayoutManager = new LinearLayoutManager(this.ʻ.getContext(), 0, false);
        this.ʻ.setLayoutManager(linearLayoutManager);
        this.ʻ.setUnInterceptOnRight(true);
        if (MinimumFactory.getBoolValue(ContentManager.getInstant().getContext())) {
            this.ʻ.setLayoutDirection(0);
            linearLayoutManager.ˊ(true);
        }
        this.ʻ.ॱ(new RecyclerView.n(this) {
            final /* synthetic */ DetailScreenCard ˋ;

            {
                this.ˋ = r1;
            }

            public void ˎ(RecyclerView recyclerView, int i) {
                this.ˋ.ॱˋ = i;
                if (i == 0) {
                    evr.ˊ().ˎ(recyclerView);
                }
            }

            public void ˊ(RecyclerView recyclerView, int i, int i2) {
                evr.ˊ().ॱ(this.ˋ.ॱˋ);
            }
        });
        this.ʻ.setAdapter(eVar);
        eVar.ˊ();
        evr.ˊ().ˋ(this.ʻ);
    }

    private boolean ˏ(String str) {
        for (DetailVideoInfo ʽ : this.ॱˎ) {
            if (str.equals(ʽ.ʽ())) {
                this.ॱᐝ.remove(str);
                return true;
            }
        }
        return false;
    }

    public void ॱ() {
        evr.ˊ().ˎ(this.ʻ);
    }

    private void ˎ(View view, int i, int i2) {
        LayoutParams layoutParams = (LinearLayout.LayoutParams) view.getLayoutParams();
        if (layoutParams == null) {
            layoutParams = new LinearLayout.LayoutParams(this.ˊॱ, this.ˏॱ);
        }
        layoutParams.width = this.ˊॱ;
        layoutParams.height = this.ˏॱ;
        if (i == 0) {
            layoutParams.setMarginStart(dra.ˋ);
            layoutParams.setMarginEnd(0);
        } else if (i > 0 && i < i2) {
            layoutParams.setMarginStart(this.ʽ);
            layoutParams.setMarginEnd(0);
        }
        if (i == i2 - 1) {
            layoutParams.setMarginStart(this.ʽ);
            layoutParams.setMarginEnd(dra.ˋ);
        }
        view.setLayoutParams(layoutParams);
    }

    private void ˏ(View view, int i, int i2) {
        LayoutParams layoutParams = (LinearLayout.LayoutParams) view.getLayoutParams();
        if (layoutParams == null) {
            layoutParams = new LinearLayout.LayoutParams(this.ˊॱ, this.ˏॱ);
        }
        layoutParams.width = this.ˊॱ;
        layoutParams.height = this.ˏॱ;
        if (i == 0) {
            layoutParams.setMarginStart(0);
            layoutParams.setMarginEnd(dra.ˋ);
        } else if (i > 0 && i < i2) {
            layoutParams.setMarginStart(0);
            layoutParams.setMarginEnd(this.ʽ);
        }
        if (i == i2 - 1) {
            layoutParams.setMarginStart(dra.ˋ);
            layoutParams.setMarginEnd(this.ʽ);
        }
        view.setLayoutParams(layoutParams);
    }

    public void ˊ() {
        ActivityUtil.unregisterReceiver(ContentManager.getInstant().getContext(), this.ʻॱ);
        super.ˊ();
    }

    public void ॱ(boolean z) {
        this.ͺ = z;
    }
}
